####REPLICATION FOR FIGURES IN ASH AND SHAPOVALOV (2022)######

#####2019 Sluga Naroda Parl Results#####

library(automap)
library(data.table)
library(raster) ##WAy of uploading rasters
library(rgdal) ##Geospatial Data Abstraction Library
library(rworldmap) ##Essentially a worldmap basemap
library(rgeos) #Many raster editing commands
library(sp) #automatically downloads with rgdal
library(gstat) #useful for interpolation
library(RColorBrewer)
library(tmap)
library(latticeExtra)
library(maptools)

setwd("~")
district <- readOGR(dsn=".", layer="electoral_district_ukr",GDAL1_integer64=TRUE)
district@data[["SN19"]]
district@data$SN19[district@data$SN19 ==0] <-NA
tm_shape(district)+ tm_borders()+tm_fill(col = 'SN19',title = "Vote Share",n=10, palette="Greens")+tm_layout(legend.outside=TRUE,legend.outside.size = .15,frame = FALSE)
district@data$SN_MAJOR[district@data$SN_MAJOR ==0] <-NA
tm_shape(district)+ tm_borders()+tm_fill(col = 'SN_MAJOR',title = "Vote Share",n=10, palette="Greens")+tm_layout(legend.outside=TRUE,legend.outside.size = .15,frame = FALSE)

###FIGURE 1 APPENDIX###

district <- readOGR(dsn="UKR_adm", layer="UKR_adm1",GDAL1_integer64=TRUE)
bg <- readOGR(dsn="UKR_adm", layer="UKR_adm0",GDAL1_integer64=TRUE)
plot(bg,col="yello")
tm_shape(district)+tm_borders()+tm_fill(col = 'LANG_MIX_P',title = "Mixed Lang. Use",n=10, colorNA="Yellow", palette="Blues")+tm_layout(legend.outside=TRUE,legend.outside.size = .15,frame = FALSE)+tm_shape(bg)+tm_borders(col="Grey")

